package com.csi.service.impl;

import com.csi.domain.Employee;
import com.csi.domain.Hotel;
import com.csi.domain.vo.EmployeeDetail;
import com.csi.mapper.LoginMapper;
import com.csi.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    @Override
    public List<Object> findName(String platForm) {
        List<Object> platFormNames = new ArrayList<>();
        if ("hotel".equals(platForm)){
           platFormNames =  loginMapper.findHotelName();
        }else if ("travel".equals(platForm)){
            platFormNames = loginMapper.findAgencyName();
        }else {
            Hotel hotel = new Hotel();
            hotel.setId(0);
            hotel.setHotelName("协同管理平台");
            platFormNames.add(hotel);
        }
        return platFormNames;
    }

    @Override
    public Employee login(Employee employee) {
        if ("travel".equals(employee.getType())){
            employee.setTravelId(employee.getTypeNameId());
            employee.setHotelId(-1); //更改hotelId的默认值
        }else {
            employee.setHotelId(employee.getTypeNameId());
        }
        return  loginMapper.login(employee);

    }

    @Override
    public EmployeeDetail findByName(String username, String type, long typeNameId) {
        return loginMapper.findByName(username,type,typeNameId);
    }
}
